<%-- Config params _____________________________START --%>

<%@ attribute
	name="parentId"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentHiddenId"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentDwrService"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentSaveMethod"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentLoadMethod"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentEditFormId"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="beforeSaveFunc"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="parentSaveBtnId"
	type="java.lang.String"
	required="false"
	description="" 
%>

<%@ attribute
	name="sonsGrids"
	type="java.lang.Object"
	required="false"
	description="" 
%>

 
<%-- Gfa4ext attritutes ______________END  --%>

<%@ include file="inc/taglibs.jsp" %>

<%@ tag 
	import="org.apache.commons.beanutils.BeanUtils,java.util.LinkedHashMap"
	dynamic-attributes="dynamicAttributes"
	description="Class for creating and editable grid. " %>
		
<extutil:processTagAttributes 
		configVar="configMap" 
		eventsVar="eventsMap" 
		include="*" 
		exclude="items"
		tagJspContext="<%=jspContext %>"
		dynamicAttributes="${dynamicAttributes}" />	
	
	<jsp:doBody />
	
	<%
		LinkedHashMap<String, String> configureMap = (LinkedHashMap<String, String>)jspContext.getAttribute("configMap");
	%>

	
	<%-- Process JSP body --%>
	<script>
		Ext.onReady(function(){	
			setTimeout(function(){

				// Parent Config
				var parentConfig = {};
			    parentConfig.parentId = <%= configureMap.get("parentId") %>;
				parentConfig.parentHiddenId = <%= configureMap.get("parentHiddenId") %>;
				parentConfig.parentDwrService = <%= configureMap.get("parentDwrService") %>;
				parentConfig.parentSaveMethod = <%= configureMap.get("parentSaveMethod") %>;
				parentConfig.parentLoadMethod = <%= configureMap.get("parentLoadMethod") %>;
				parentConfig.parentEditFormId = <%= configureMap.get("parentEditFormId") %>;
				<%
					String strBeforeSaveFunc = configureMap.get("beforeSaveFunc");
					if( strBeforeSaveFunc != null && strBeforeSaveFunc.length() > 0){
						%>
						parentConfig.beforeSaveFunc = <%= strBeforeSaveFunc %>;
						<%
					}
				%>

				// Sons Config
				<%
				String sonsGrids = configureMap.get("sonsGrids");
				if(sonsGrids.startsWith("'")){
					sonsGrids = sonsGrids.substring(1, sonsGrids.length()-1);
				}
				if(sonsGrids.endsWith("'")){
					sonsGrids = sonsGrids.substring(0, sonsGrids.length()-2);
				}
				%>
				var sonsGrids = [<%= sonsGrids %>];
			    
			    var saveConfig = {parentConfig:parentConfig, sonsGrids:sonsGrids};
			    
			    // bind save button click event
			    Ext.get(<%= configureMap.get("parentSaveBtnId") %>).addListener('click', Gfa.widgets.BaseGrid.saveParentAndChildren, saveConfig);
			    
			    // load father record
			    Gfa.widgets.BaseGrid.loadParent(parentConfig);
			}, 100);
	    });
	</script>	    